package com.shdanyan.dto;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shdanyan.domain.sys.SysUserInfo;

public class UserInfoDTO {
    private static final String ROLE_USER = "ROLE_USER";

    private String username;

    private String password;
    private String usertype;
    private Integer enabled;
    private String qq;

    private String email;
    private String tel;

    public UserInfoDTO(@JsonProperty("password") String password,
            @JsonProperty("username") String username) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsertype() {
        return usertype;
    }

    public void setUsertype(String usertype) {
        this.usertype = usertype;
    }

    public Integer getEnabled() {
        return enabled;
    }

    public void setEnabled(Integer enabled) {
        this.enabled = enabled;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public static String getRoleUser() {
        return ROLE_USER;
    }

    public SysUserInfo toUser() {
        SysUserInfo userInfo = new SysUserInfo();
        // userInfo.setRole(new Role());
        userInfo.setPassword(new BCryptPasswordEncoder().encode(password));
        userInfo.setUsername(username);
        return userInfo;
    }

    public UsernamePasswordAuthenticationToken toAuthenticationToken() {
        return new UsernamePasswordAuthenticationToken(this.getUsername(), this.getPassword());
    }

}